// 把第三方 esm模块 动态注册到 nestjs 的 DI 容器中
// 参考：https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory

import { FactoryProvider } from '@nestjs/common';
import { importEsmPackage } from './import-esm-package';

// 注册 esm 模块的工厂函数
export const esmProvider: Function = (params: {
  provideName: string;
  packageName: string;
}) => {
  return {
    provide: params.provideName,
    useFactory: () => importEsmPackage(params.packageName),
  } as FactoryProvider;
};
